<?php
use coreLib\ErrorClass\Error;
use coreLib\ResponseClass\Response;

/*
 * 正则验证
 */

class Regexp {

	//验证restful参数格式是否正确
	function restFulV($response,$route,$paramName,$rule){

		//取出正则验证规则
   		$pattern 	 = $GLOBALS['regexpSettings'][$rule];
   		$paramsValue = $route->restfulParams[$paramName];

   		if($pattern && $paramsValue){
   			if(!preg_match($pattern, $paramsValue)){
				  $response->responseData(false,"参数:".$paramName."格式不正确");
			   }
   		}
   		return $paramsValue;
	}

	//验证body参数格式是否正确
	function bodyV($response,$route,$paramName,$rule){

		//取出正则验证规则
   		$pattern 	 = $GLOBALS['regexpSettings'][$rule];
   		$paramsValue = $route->bodyParams[$paramName];


   		if($pattern && $paramsValue){
   			if(!preg_match($pattern, $paramsValue)){
				  $response->responseData(false,"参数:".$paramName."格式不正确");
			   }
   		}

   		return $paramsValue;

	}
}
?>